$(function () {
    $("#jqGrid").jqGrid({
        url: '../sysworklog/list',
        datatype: "json",
        colModel: [			
        	{ label: '工号', name: 'workno',width: 80 }, 			
			{ label: '姓名', name: 'workname', width: 80 }, 	
			{ label: '账号', name: 'usernamelogin', width: 100 }, 			
			{ label: '操作时间', name: 'createtimelogin', width: 180 }, 			
			{ label: '操作结果', name: 'contectlogin',frozen : true,  width: 180 }, 			
			{ label: '备注', name: 'memo',frozen : true,  width: 300 }, 
			{ label: 'id', name: 'id', width: 50,hidden:true, key: true },
			{ label: '操作IP地址', name: 'remoteaddr', width: 150 }, 			
			{ label: '请求URL', name: 'requesturi', width: 200,hidden:true }, 			
			{ label: '操作方式', name: 'methodlogin', width: 80 }, 			
			{ label: '选择数据时间', name: 'datatimeselect', width: 100 }, 								
			{ label: '员工身份证号', name: 'peoplecard', hidden:true,width: 200 }			
        ],
		viewrecords: true,
        height: $(window).height()-120,
        rowNum: 30,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        width:window.screen.availWidth-250,  
        autowidth: false,  
        shrinkToFit: false,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit",  
            sort:"sort",//需要排序的列
            order: "order"
        },
        gridComplete:function(){
        	$('.ui-jqgrid-bdiv').scrollTop(0);
        	//隐藏grid底部滚动条
        	//$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
    jQuery("#jqGrid").jqGrid('setFrozenColumns');
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		value:null,
		calTime:null,
		title: null,
		sysWorkLog: {}
	},
	methods: {
		query: function () {
			vm.calTime=$("#calTime").val();
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.sysWorkLog = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.sysWorkLog.id == null ? "../sysworklog/save" : "../sysworklog/update";
			$.ajax({
				type: "POST",
			    url: url,
			    data: JSON.stringify(vm.sysWorkLog),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../sysworklog/delete",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../sysworklog/info/"+id, function(r){
                vm.sysWorkLog = r.sysWorkLog;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
				postData:{'value': vm.value,"calTime":vm.calTime},
                page:page
            }).trigger("reloadGrid");
		}
	}
});